package com.xsm.view;
import com.xsm.activitygroup.R;

import android.R.raw;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Mydialog {
	Dialog dialog;
	Context context;
	View view,v;
	Button Cancel,Ensure;
	TextView ContenttextView,titleTextView;
	OnClickListener listener;
	String text;
	
	public Mydialog(Context context,String text){
		this.context=context;
		this.text=text;
		view=LayoutInflater.from(context).inflate(R.layout.dialog, null);
		ContenttextView=(TextView)view.findViewById(R.id.dialogtext);
		titleTextView=(TextView)view.findViewById(R.id.dtitle);
		v=view.findViewById(R.id.v);
		ContenttextView.setText(text);
		Cancel=(Button)view.findViewById(R.id.bt1);
		Ensure=(Button)view.findViewById(R.id.bt2);
		Cancel.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				dissmissDialog();
			}
		});
		dialog=new Dialog(context,R.style.MyDialog);
		dialog.setContentView(view);
		dialog.setCanceledOnTouchOutside(false);
		
//		Window dialogWindow = dialog.getWindow();
//	    WindowManager.LayoutParams lp = dialogWindow.getAttributes();
//	    dialogWindow.setGravity(Gravity.CENTER);
//	   
//	    WindowManager m = activity.getWindowManager();  
//	    Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
//        WindowManager.LayoutParams p = activity.getWindow().getAttributes(); // 获取对话框当前的参数值
//        p.height = (int) (d.getHeight() * 0.4); // 高度设置为屏幕的0.6
//        p.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.95
//        dialogWindow.setAttributes(p);
//        Log.d("my", p.height+"h"+p.width);
	}
	
public void setParams(WindowManager.LayoutParams p){
	Window dialogWindow = dialog.getWindow();
	 dialogWindow.setAttributes(p);
}
	
public void showDialog(){
	Ensure.setOnClickListener(this.listener);
	dialog.show();
}
public void dissmissDialog(){
	dialog.dismiss();
}
public void CancelText(String s){
	Cancel.setVisibility(view.VISIBLE);
	Cancel.setText(s);
}
public void setEnsureText(String s){
	Ensure.setVisibility(view.VISIBLE);
	Ensure.setText(s);
}
public void settitle(String text){
	titleTextView.setText(text);
}
public void setEnsurelistener(OnClickListener listener){	
	v.setVisibility(view.VISIBLE);
	Ensure.setVisibility(view.VISIBLE);
	Cancel.setVisibility(view.VISIBLE);
	this.listener=listener;
}

}
